package com.monitor.controller;


import com.monitor.util.Result;
import com.monitor.webservice.SendDataActionServiceLocator;
import com.monitor.webservice.SendDataSoapBindingStub;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * webservice 接口
 * </p>
 *
 * @author LX
 * @since 2018-09-09
 */
@RestController
@Transactional
@RequestMapping("/webServiceController")
@Api(description="webservice 接口")
public class ErpWebServiceController {
    @RequestMapping("/sendAllData")
    @ApiOperation("同步所有数据-初试密码的启动,")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "password", value = "密码", required = false, dataType = "int", paramType = "query") //123456
    })
    public @ResponseBody
    Result<String> sendAllData( String name,
                                             String value) {
        Result<String> result=new Result<>();
        try{
          String  password="123456";
            		SendDataActionServiceLocator locator = new SendDataActionServiceLocator();
//            locator.
//            SendDataActionServiceLocator locator = new SendDataActionServiceLocator();
            SendDataSoapBindingStub sendDataSoapBindingStub= (SendDataSoapBindingStub)locator.getSendData();
            String s = sendDataSoapBindingStub.sendAllData(password, name, value);//erp_bidata_list 表的 name,和value
//            SendDataActionServiceTestCase.
//            SendDataActionSendDataActionService
            result.setCount(1);
            result.setData(s);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }    @RequestMapping("/SendText3")
    @ApiOperation("下发报文3,")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "password", value = "密码", required = false, dataType = "int", paramType = "query") //123456
    })
    public @ResponseBody
    Result<String> SendText3(  String parameter_name,
                              String parameter_value, String Car_type, String car_plate) {
        //Car_type：挂车 ；
        //car_plate：车牌
        Result<String> result=new Result<>();
        try{
          String  password="123456";
            SendDataActionServiceLocator locator = new SendDataActionServiceLocator();
            SendDataSoapBindingStub sendDataSoapBindingStub= (SendDataSoapBindingStub)locator.getSendData();//erp_bidata_list 字段
            String s = sendDataSoapBindingStub.sendText3(password,parameter_name,parameter_value,Car_type,car_plate); //,name value
//            SendDataActionServiceTestCase.
//            SendDataActionSendDataActionService
            result.setCount(1);
            result.setData(s);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

//    使用任何报文，通用模板下发
//    /**
//     *
//     * @param password
//     *            密码
//     * @param parameter_name  （来自 erp_bidata_list 字段）
//     *            定位器 or 传感器
//     * @param parameter_value （来自 erp_bidata_list 字段）
//     *            id
//     * @param data
//     *            下发的32位字节
//     * @return String  密码错误   设备离线   数据长度问题   成功   异常
//     */
//    public String SendOnlyData(String password, String parameter_name,
//                               String parameter_value, String data) ;
//
//
//
//    SendMouldData（"123456","定位器"，“830808”“7e0205f00200000002010000000100020000000080000003f00c0d0601000406”）
    @RequestMapping("/sendMouldData")
    @ApiOperation("使用任何报文，通用模板下发,")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "password", value = "密码", required = false, dataType = "int", paramType = "query") //123456
    })
    public @ResponseBody
    Result<String> sendMouldData( String parameter_name  ,String parameter_value , String data) {
        Result<String> result=new Result<>();
        try{
          String  password="123456";
            SendDataActionServiceLocator locator = new SendDataActionServiceLocator();
            SendDataSoapBindingStub sendDataSoapBindingStub= (SendDataSoapBindingStub)locator.getSendData();
            String s = sendDataSoapBindingStub.sendMouldData(password,parameter_name,parameter_value,data);
//            SendDataActionServiceTestCase.
//            SendDataActionSendDataActionService
            result.setCount(1);
            result.setData(s);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/sendText2")
    @ApiOperation("下发报文2 - 下发数据的启动,")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "password", value = "密码", required = false, dataType = "int", paramType = "query") //123456
    })
    public @ResponseBody
    Result<String> sendText2(String parameter_name,
                                            String parameter_value, String Car_type, String axis, String tire,
                                            int device_type, int device_id, double max_pressure,
                                            double min_pressure) {
//           下发数据的启动,
//        axis：轴距  从1开始
//        tire：胎位 从 0  开始
//        device_type:0 是传感器， 1是定位器
//        device_id ： ID 号
//        max_pressure ：上胎压
//        min_pressure：下胎压
//        parameter_value
        Result<String> result=new Result<>();
        try{
          String  password="123456";
            SendDataActionServiceLocator locator = new SendDataActionServiceLocator();
            SendDataSoapBindingStub sendDataSoapBindingStub= (SendDataSoapBindingStub)locator.getSendData();
            String s = sendDataSoapBindingStub.sendText2(password,parameter_name,parameter_value,Car_type,axis,tire,device_type,device_id,max_pressure,min_pressure);
//            SendDataActionServiceTestCase.
//            SendDataActionSendDataActionService
            result.setCount(1);
            result.setData(s);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

}
